#include "tgaimage.h"
#include "os_helper.h"
#include "logging.h"

#include <iostream>
#include <string>
#include <source_location>

#include <bit>
#include <format>

static void log(std::string level, std::string message,
	const std::source_location& location = std::source_location::current())
{
	std::cout << level
		<< location.file_name() << " in function "
		<< location.function_name() << " at "
		<< location.line() << ':' << location.column() << ": "
		<< message << '\n';

	std::cout << " location: " << location.file_name() << ":" << location.line() << "\n";
}

template<class... Args>
inline void print(const std::format_string<Args...> fmt, Args&&... args)
{
	std::cout << std::vformat(fmt.get(), std::make_format_args(args...)) << "\n";
}

int main()
{
	TGAImage image;
	std::string filepath("D:/workspace/git_cpp/linuxstudy/util/3d/fileformat/tga/obj/diablo3_pose/diablo3_pose_diffuse.tga");
	bool res = image.is_new_tga(filepath);
	if (res) {
		std::cout << "file " << filepath << "is new tga" << std::endl;
	}
	else {
		std::cout << "file " << filepath << "is not new tga" << std::endl;
	}

	bool ordering = os_helper::is_intel_byte_ordering();
	if (ordering) {
		std::cout << "is intel byte ordering" << std::endl;
	}
	else {
		std::cout << "is motorola byte ordering" << std::endl;
	}

	if (image.read_from_tga_file(filepath)) {
		logging::info("success to read tga file {}", filepath);
	}
	return 0;
}